﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using RestSharp;
using WeiTalk.OAuth.Sina;
using System.Text.RegularExpressions;
using System.Threading;
using WeiTalk.SinaEntities;
using WeiTalk.OAuth;

namespace WeiTalk
{
    public partial class MainPage : PhoneApplicationPage
    {
        
        string accessToken = String.Empty;
 
        // 构造函数
        public MainPage()
        {
            InitializeComponent();
        }

        private void btnOAuth_Click(object sender, RoutedEventArgs e)
        {
            tbtStatus.Text = "认证中...";
            OAuthBase oauth = new WeiTalk.OAuth.Sina.OAuth(tbUserName.Text, pbPassword.Password, WeiTalk.OAuth.Utility.ConsumerKey);

            oauth.Authenticate((accessToken) =>
            {
                Dispatcher.BeginInvoke(() =>
                {
                    WeiBoUtility.ShowToast("认证成功！正在跳转页面...");
                    WeiTalk.OAuth.Utility.AccessToken = accessToken;
                    this.NavigationService.Navigate(new Uri("/ContentDefaultPage.xaml", UriKind.Relative));
                });
            }
            ,
            (ex) =>
            {
                Dispatcher.BeginInvoke(() =>
                    {
                        tbtStatus.Text = ex;
                    });
            });

            tbtStatus.Text = "";
           
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            tbtStatus.Text = "";
            TitlePanel.RenderTransform = new CompositeTransform() { TranslateY = -200 };
            base.OnNavigatedFrom(e);
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            tbtStatus.Text = "";
            sbTitle.Begin();
        }
       
    }
}